package br.com.j7.jdesk.library.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;

public class AnnotationUtils {

	public static <T> T getAnnotation(Class<? extends Annotation> annotation, Field field, String method ){
		if(field.isAnnotationPresent(annotation)){
			try {
				Object obj = annotation;
				obj = field.getAnnotation(annotation);
				if(obj != null){
					return loadMethodObject(method, obj);
				}
			} catch ( Exception e) {
				throw new RuntimeException(e);
			}
		}
		return null;
	}

	@SuppressWarnings("unchecked")
	private static <T> T loadMethodObject(String method, Object obj) throws Exception {
		return (T) ReflectionUtils.invokeNoArgsMethod(obj, method);
	}
}
